package net.jkdmanager.server.services.model;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import net.jkdmanager.common.api.model.Application;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("modelService")
@Transactional
public class ModelServiceImpl implements ModelService {

	@PersistenceContext
	private EntityManager entityManager;
	
	public Long createApplication(Application application) {
		entityManager.persist(application);
		return application.getId();
	}
	
	@SuppressWarnings("unchecked")
	public List<Application> getAllApplications() {
		return (List<Application>)entityManager.createQuery("from Application").getResultList();
	}
	
	public Application getApplication(long appId) {
		return entityManager.find(Application.class, appId);
	}
	
}
